package com.jprocms.module.cms.dal.dataobject.investigateitem;

import cn.hutool.core.collection.CollUtil;
import com.jpro.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jprocms.module.cms.dal.dataobject.investigateitemoption.InvestigateItemOptionDO;
import lombok.*;

import java.util.List;

/**
 * 问卷选项 DO
 *
 * @author jprocms
 */
@TableName("cms_investigate_item")
@KeySequence("cms_investigate_item_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库，可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InvestigateItemDO extends BaseDO {

    private static final long serialVersionUID = 1L;

    /**
     * 总票数
     */
    public int getTotal() {
        final List<InvestigateItemOptionDO> investigateItemOptionDOS = getOptions();
        if (CollUtil.isEmpty(investigateItemOptionDOS)) {
            return 0;
        }
        return investigateItemOptionDOS.stream().mapToInt(InvestigateItemOptionDO::getOptionCount).sum();
    }

    /**
     * ID
     */
    @TableId
    private Long id;
    /**
     * 站点ID
     */
    private Long siteId;
    /**
     * 问卷ID
     */
    private Long investigateId;
    /**
     * 标题
     */
    private String title;
    /**
     * 排序
     */
    private Integer itemSort;
    /**
     * 是否多选
     */
    private Boolean isMultiple;
    /**
     * 是否问答
     */
    private Boolean isQa;
    /**
     * 题目的选项
     */
    @TableField(exist = false)
    private List<InvestigateItemOptionDO> options;

}
